package com.grapro.visitorsystem.controller;

import com.grapro.visitorsystem.entity.JsonResult;
import com.grapro.visitorsystem.exception.CustomException;
import com.grapro.visitorsystem.service.UserService;
import com.grapro.visitorsystem.service.VisitorService;
import com.grapro.visitorsystem.utils.json.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private VisitorService visitorService;

    @RequestMapping(value = "/get_user/{userId}", method = RequestMethod.POST)
    public JsonResult user(@PathVariable String userId) {
        System.out.println("userId:" + userId);
        return JsonUtil.ok(userService.getUserById(userId));
    }

    @RequestMapping(value = "/get_visitor/{visitorId}", method = RequestMethod.GET)
    public JsonResult visitor(@PathVariable String visitorId) {
        System.out.println("visitorId:" + visitorId);
        return JsonUtil.ok("get_visitor", visitorService.getVisitorById(visitorId));
    }

    @RequestMapping(value = "/test_coustom_excption", method = RequestMethod.GET)
    public JsonResult testExcetpotion(Integer number) {
        System.out.println("testExcetpotion");
        if (null == number){
            throw new CustomException(110,"number不能为空，其实是400");
        }
        return JsonUtil.ok("sdasdas");
    }

    @RequestMapping("/exce")
    public Object showInfo() {
        System.err.println("dddddddddddddd");
        String info = "你好";
        int a = 1 / 0;
        return info;
    }
}
